home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 2010 April / PCWorld0410.iso / hity wydania / Blender 2.49b / blender-2.49b-windows.exe / $_4_ / .blender / scripts / save_theme.py < prev    next >
Text File  |  2009-08-31  |  5KB  |  144 lines

  1. #!BPY
  2.  
  3. """
  4. Name: 'Save Current Theme...'
  5. Blender: 242
  6. Group: 'Export'
  7. Tooltip: 'Save current theme as a BPython script'
  8. """
  9.  
  10. __author__ = "Willian P. Germano"
  11. __url__ = ("blender", "blenderartists.org")
  12. __version__ = "2.43 2006/12/30"
  13.  
  14. __bpydoc__ = """\
  15. This script saves the current Theme in Blender as a Blender Python script.
  16.  
  17. Usage:
  18.  
  19. Use Blender's Theme tab in the User Preferences window to create and name your
  20. theme, then run this script from the File->Export menu to save it.
  21.  
  22. It is saved as a bpython script, meaning that you can simply run it to change
  23. the current theme.  By default it is currently saved under the
  24. "Misc" group, available only from the Scripts window "Scripts->Misc" menu.
  25.  
  26. To appear in the menu, a theme saved with this script must be put in your
  27. Blender's scripts dir, that's what happens by default when you save one by
  28. yourself.  If you don't know where this dir is, running
  29.  
  30. import Blender<br>print Blender.Get("scriptsdir")
  31.  
  32. on the Text Editor window (use menu or ALT+P to run it) will write the path on
  33. the console.
  34.  
  35. Remember to edit your exported theme's source file to put your name and
  36. some information on it before sharing it with others.
  37. """
  38.  
  39. # $Id: save_theme.py 14530 2008-04-23 14:04:05Z campbellbarton $
  40. #
  41. # --------------------------------------------------------------------------
  42. # Copyright (C) 2004: Willian P. Germano, wgermano _at_ ig com br
  43. # --------------------------------------------------------------------------
  44. # The scripts generated by this script are put under Public Domain by
  45. # default, but you are free to edit the ones you generate with this script
  46. # and change their license to another one of your choice.
  47. # --------------------------------------------------------------------------
  48. # ***** BEGIN GPL LICENSE BLOCK *****
  49. #
  50. # Copyright (C) 2005: Willian P. Germano, wgermano _at_ ig.com.br
  51. #
  52. # This program is free software; you can redistribute it and/or
  53. # modify it under the terms of the GNU General Public License
  54. # as published by the Free Software Foundation; either version 2
  55. # of the License, or (at your option) any later version.
  56. #
  57. # This program is distributed in the hope that it will be useful,
  58. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  59. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.    See the
  60. # GNU General Public License for more details.
  61. #
  62. # You should have received a copy of the GNU General Public License
  63. # along with this program; if not, write to the Free Software Foundation,
  64. # Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
  65. #
  66. # ***** END GPL LICENCE BLOCK *****
  67. # --------------------------------------------------------------------------
  68.  
  69. import Blender
  70. from Blender.Window import Theme, FileSelector
  71.  
  72. theme = Theme.Get()[0] # get current theme
  73.  
  74. # default filename: theme's name + '_theme.py' in user's scripts dir:
  75. default_fname = Blender.Get("scriptsdir")
  76. if (default_fname):
  77.     default_fname = Blender.sys.join(default_fname, theme.name + '_theme.py')
  78. else:
  79.     default_fname = theme.name + '_theme.py'
  80.     
  81. default_fname = default_fname.replace(' ','_')
  82.  
  83. def write_theme(filename):
  84.     "Write the current theme as a bpython script"
  85.  
  86.     if not filename.endswith('.py'): filename += '.py'
  87.  
  88.     fout = file(filename, "w")
  89.  
  90.     fout.write("""#!BPY
  91.  
  92. # \"\"\"
  93. # Name: '%s'
  94. # Blender: 242
  95. # Group: 'Themes'
  96. # Tooltip: 'Change current theme'
  97. # \"\"\"
  98.  
  99. __%s__ = "????"
  100. __%s__ = "2.43"
  101. __%s__ = ["blender"]
  102. __%s__ = \"\"\"\\
  103. You can edit this section to write something about your script that can
  104. be read then with the Scripts Help Browser script in Blender.
  105.  
  106. Remember to also set author, version and possibly url(s) above.  You can also
  107. define an __email__ tag, check some bundled script's source for examples.
  108. \"\"\"
  109.  
  110. # This script was automatically generated by the save_theme.py bpython script.
  111. # By default, these generated scripts are released as Public Domain, but you
  112. # are free to change the license of the scripts you generate with
  113. # save_theme.py before releasing them.
  114.  
  115. import Blender
  116. from Blender.Window import Theme
  117.  
  118. theme = Theme.New('%s')
  119. """ % (theme.name, "author", "version", "url", "bpydoc", theme.name))
  120.  
  121.     for tsp in theme.get(): # 
  122.         command = "\n%s = theme.get('%s')" % (tsp, tsp)
  123.         fout.write(command + "\n")
  124.         exec(command)
  125.         exec("vars = dir(%s)" % tsp)
  126.         vars.remove('theme')
  127.  
  128.         for var in vars:
  129.             v = "%s.%s" % (tsp, var)
  130.             exec("value = %s" % v)
  131.             if type(value) == str:
  132.                 fout.write("%s = '%s'\n" % (v, value))
  133.             else:
  134.                 fout.write("%s = %s\n" % (v, value))
  135.  
  136.     fout.write('\nBlender.Redraw(-1)')
  137.     fout.close()
  138.     try:
  139.         Blender.UpdateMenus()
  140.     except:
  141.         Blender.Draw.PupMenu("Warning - check console!%t|Menus could not be automatically updated")
  142.  
  143. FileSelector(write_theme, "Save Current Theme", default_fname)
  144.